﻿using Glorysoft.EAP.Core.Entities.DB.Contract;
using System;
using System.Collections.Generic;
using System.Text;

namespace Glorysoft.EAP.Core.Entities.DB.Service
{
    public class RPT_RUN_HISTORY_TEMPService //: FreeSqlContext//, IRPT_RUN_HISTORY_TEMPService
    {
        /// <summary>
        /// 根据主键ID 删除数据
        /// </summary>
        /// <param name="id">主键ID</param>
        /// <returns>执行结果</returns>
        public static int Delete(int id)
        {
            //return FreeSqlContext.FreeSqlConnect().Delete<RPT_MSG_HISTORY>(id).ExecuteAffrows();
            return FreeSqlContext.Delete<RPT_RUN_HISTORY_TEMP>(id);
        }
        /// <summary>
        /// 新增数据
        /// </summary>
        /// <param name="entity">实体对象</param>
        /// <returns>执行结果</returns>
        public static int Insert(RPT_RUN_HISTORY_TEMP entity)
        {
            return FreeSqlContext.Insert<RPT_RUN_HISTORY_TEMP>(entity);
        }
        /// <summary>
        /// 获取所有数据
        /// </summary>
        /// <returns>数据集合</returns>
        public static IList<RPT_RUN_HISTORY_TEMP> SelectAll()
        {
            return FreeSqlContext.SelectAll<RPT_RUN_HISTORY_TEMP>();
        }
        /// <summary>
        /// 根据主键ID获取数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns>实体对象</returns>
        public static RPT_RUN_HISTORY_TEMP SelectById(int id)
        {
            return FreeSqlContext.SelectById<RPT_RUN_HISTORY_TEMP>(id);
        }

        /// <summary>
        /// 根据设备ID，LOTID，ProductID,获取数据集合
        /// </summary>
        /// <param name="eqpID">设备ID</param>
        /// <param name="lotID">LOTID</param>
        /// <param name="productID">ProductID</param>
        /// <returns>数据集合</returns>
        public static IList<RPT_RUN_HISTORY_TEMP> SelectByEQPID(string eqpID, string lotID, string productID)
        {
            return FreeSqlContext.FreeSqlConnect.Select<RPT_RUN_HISTORY_TEMP>().Where(t => t.EQP_ID == eqpID && t.LOT_ID == lotID && t.PRODUCT_ID == productID).ToList();
        }
        /// <summary>
        /// 更新数据信息
        /// </summary>
        /// <param name="entity">实体类对象</param>
        /// <returns>执行结果</returns>
        public static int Update(RPT_RUN_HISTORY_TEMP entity)
        {
            return FreeSqlContext.Update(entity);
        }
        /// <summary>
        /// 根据设备ID，LOTID,获取数据对象
        /// </summary>
        /// <param name="eqpID">设备ID</param>
        /// <param name="lotID">LOTID</param>
        /// <returns>实体对象</returns>
        public static RPT_RUN_HISTORY_TEMP SelectByeqpID(string eqpID, string lotID)
        {
            return FreeSqlContext.FreeSqlConnect.Select<RPT_RUN_HISTORY_TEMP>().Where(t => t.EQP_ID == eqpID && t.LOT_ID == lotID  && t.TRACKIN_TIME != null && t.TRACKIN_TIME != "").First(); //&& t.PRODUCT_ID == productID
        }
        public static RPT_RUN_HISTORY_TEMP SelectByeqpIDAndLotID(string eqpID, string lotID)
        {
            return FreeSqlContext.FreeSqlConnect.Select<RPT_RUN_HISTORY_TEMP>().Where(t => t.EQP_ID == eqpID && t.LOT_ID == lotID  && t.TRACKIN_TIME != null && t.TRACKIN_TIME != "").First(); //&& t.PRODUCT_ID == productID
        }
        public static RPT_RUN_HISTORY_TEMP SelectByeqpIDAndLotIDProductID(string eqpID, string lotID)
        {
            return FreeSqlContext.FreeSqlConnect.Select<RPT_RUN_HISTORY_TEMP>().Where(t => t.EQP_ID == eqpID && t.LOT_ID == lotID  && t.TRACKIN_TIME != null && t.TRACKIN_TIME != "" ).First(); //&& t.PRODUCT_ID == productID
        }

        public static IList<RPT_RUN_HISTORY_TEMP> QueryRunHisTempByEQPID(string eqpID)
        {
            return FreeSqlContext.FreeSqlConnect.Select<RPT_RUN_HISTORY_TEMP>().Where(t => t.EQP_ID == eqpID && t.TRACKIN_TIME != null && t.TRACKIN_TIME != "" && t.START_TIME != null && t.START_TIME != "" && t.END_TIME != null && t.END_TIME != "").ToList();
        }
    }
}
